package com.feng.animations.views;

import com.feng.animations.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

public class TweenViewByXML extends View 
{
	private Animation anima = null;
	private Bitmap pict = null;
	private Context context = null;

	public TweenViewByXML(Context context) 
	{
		super(context);
		
		this.pict = BitmapFactory.decodeResource(getResources(), R.drawable.drop);
		this.context = context;
	}

	@Override
	protected void onDraw(Canvas canvas) 
	{
		super.onDraw(canvas);
		
		canvas.drawBitmap(this.pict, 0, 0, null);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{
		int resID = -1;
		switch (keyCode)
		{
			case KeyEvent.KEYCODE_DPAD_UP:
				resID = R.anim.alpha_anim;
				break;
			case KeyEvent.KEYCODE_DPAD_DOWN:
				resID = R.anim.scale_anim;
				break;
			case KeyEvent.KEYCODE_DPAD_LEFT:
				resID = R.anim.translate_anim;
				break;
			case KeyEvent.KEYCODE_DPAD_RIGHT:
				resID = R.anim.rotate_anim;
				break;
			default:
				return false;
		}
		this.anima = AnimationUtils.loadAnimation(this.context, resID);
		this.startAnimation(this.anima);
		return true;
	}
	

}
